package com.woniu.humanresource.controller;

import com.woniu.humanresource.entity.*;
import com.woniu.humanresource.exception.GeneralException;
import com.woniu.humanresource.service.CompensationSchemeService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

//企业薪酬方案
@RestController
public class CompensationSchemeController {

    @Resource
    CompensationSchemeService compensationSchemeService;


    //查询

    @PostMapping("/compensationscheme/{pageIndex}/{pageSize}")
    public ResponseText selectCompensationScheme(@PathVariable("pageIndex") int pageIndex,
                                                @PathVariable("pageSize") int pageSize,
                                                @RequestBody CompensationScheme compensationScheme){
        System.out.println("查询条件"+compensationScheme);
        System.out.println("pageIndex"+pageIndex);
        System.out.println("pageSize"+pageSize);
        ResponseText<PageBean<CompensationScheme>> responseText = null;
        try {
            PageBean<CompensationScheme> pageBean = compensationSchemeService.selectCompensationScheme(compensationScheme, pageIndex, pageSize);
            responseText = new ResponseText<>(pageBean,200,"查询成功！！！");
        }catch (Exception e){
            e.printStackTrace();
            throw new GeneralException();
        }
        return responseText;
    }


    //添加企业薪酬方案
    @PostMapping("/addcompensationscheme")
    public ResponseText addCompensationScheme(@RequestBody CompensationScheme compensationScheme){
        System.out.println("添加条件"+compensationScheme);
        ResponseText responseText=null;
        try {
            //待面试状态
            compensationSchemeService.insertCompensationScheme(compensationScheme);
            responseText=new ResponseText(null,200,"success");
        } catch (Exception e) {
            e.printStackTrace();
            throw new GeneralException();
        }
        return responseText;
    }

    //删除企业薪酬方案
    @DeleteMapping("/delecompensationscheme/{id}")
    public ResponseText deleteCompensationScheme(@PathVariable("id") int id){
        System.out.println("删除条件"+id);

        ResponseText responseText=null;
        try {
            compensationSchemeService.deleteCompensationScheme(id);
            responseText=new ResponseText(null,200,"success");
        } catch (Exception e) {
            e.printStackTrace();
            throw new GeneralException();
        }
        return responseText;
    }

    //修改企业福利
    @PutMapping("/updatecompensationscheme")
    public ResponseText updateCompensationScheme(@RequestBody CompensationScheme compensationScheme){
        System.out.println("修改条件"+compensationScheme);
        ResponseText responseText=null;
        try {
           compensationSchemeService.updateCompensationScheme(compensationScheme);
            responseText=new ResponseText<PageBean<CompensationScheme>>(null,200,"success");
        } catch (Exception e) {
            e.printStackTrace();
            throw new GeneralException();
        }
        return responseText;
    }

}
